package digui;

import utils.Times;

public class Sum1 {
    static int sum1(int n) {
        if (n <= 1) return 1;
        return n + sum1(n - 1);
    }

    static int sum2(int n) {
        if (n <= 1) return 1;
        int res = 0;
        for (int i = 0; i < n; i++) res += i;
        return res;
    }

    static int sum3(int n) {
        if (n <= 1) return 1;
        return (n * (n * 1)) / 2;
    }

    public static void main(String[] args) {
        int res1 = sum1(8);
        int res2 = sum2(6);
        int res3 = sum3(9);

        System.out.println(res1);
        System.out.println(res2);
        System.out.println(res3);

        Times.test("sum1", () -> System.out.println(sum1(10000)));
    }
}
